<?php
 
	$total_price = 0;
	$total_sales_price = 0;
	$profit_price = 0;
		 
 	$excel = $this->excel->workbook;
	$excel->setActiveSheetIndex(0);  
		
	$excel->getActiveSheet()->SetCellValue('A4', T_('Test Date'));
	$excel->getActiveSheet()->SetCellValue('B4', T_('Last Name'));
 	$excel->getActiveSheet()->SetCellValue('C4', T_('First Name'));
	$excel->getActiveSheet()->SetCellValue('D4', T_('Email Address'));
	$excel->getActiveSheet()->SetCellValue('E4', T_('Job Title'));
	$excel->getActiveSheet()->SetCellValue('F4', T_('Test'));
	$excel->getActiveSheet()->SetCellValue('G4', T_('Raw Score'));
	$excel->getActiveSheet()->SetCellValue('H4', T_('Percentile'));
	/*
	$excel->getActiveSheet()->SetCellValue('I4', T_('Shop#'));
	$excel->getActiveSheet()->SetCellValue('J4', T_('Initials'));
	$excel->getActiveSheet()->SetCellValue('K4', T_('Sales Date'));
	$excel->getActiveSheet()->SetCellValue('L4', T_('Stock Date'));
	$excel->getActiveSheet()->SetCellValue('M4', T_('Retail Price DKK'));
	$excel->getActiveSheet()->SetCellValue('N4', T_('Sales Price DKK'));
	$excel->getActiveSheet()->SetCellValue('O4', T_('Profit DKK'));
	*/
	$excel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
	$excel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
	$excel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
	$excel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
	$excel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
	$excel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
	$excel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
	$excel->getActiveSheet()->getColumnDimension('H')->setWidth(12);
	/*$excel->getActiveSheet()->getColumnDimension('I')->setWidth(8);
	$excel->getActiveSheet()->getColumnDimension('J')->setWidth(7);
	$excel->getActiveSheet()->getColumnDimension('K')->setWidth(10);
	$excel->getActiveSheet()->getColumnDimension('L')->setWidth(10);
	$excel->getActiveSheet()->getColumnDimension('M')->setWidth(15);
	$excel->getActiveSheet()->getColumnDimension('N')->setWidth(15);
	$excel->getActiveSheet()->getColumnDimension('O')->setWidth(15);  */       
    
    //$excel->getActiveSheet()->SetCellValue('A2', 'Quoted Euro price:    20');
	$excel->getActiveSheet()->duplicateStyleArray(
		      array(
		        'fill' => array(
		             'type'   => PHPExcel_Style_Fill::FILL_SOLID,
		             'startcolor' => array(
		                'rgb' => 'C0C0C0'
		             )
		          ),
				'borders' => array(         	          
				    'top'  => array(
		            	'style' => PHPExcel_Style_Border::BORDER_THIN,
			            'color' => array('rgb' => '000000')                	
		             ),
				    'bottom'  => array(
		            	'style' => PHPExcel_Style_Border::BORDER_THIN,
			            'color' => array('rgb' => '000000')                	
		             ),
		 	 	),		          
		      ),
		      'A2:B2'
			);
	$excel->getActiveSheet()->duplicateStyleArray(
		      array(
				'borders' => array(         	          
				    'right'  => array(
		            	'style' => PHPExcel_Style_Border::BORDER_THIN,
			            'color' => array('rgb' => '000000')                	
		             ),
		 	 	),		          
		      ),
		      'B2'
			);
			

    $price_total = 0;
    $i = 5;    

    if (!empty($list))
    {
    	
	    foreach ($list as $num => $row)
	    {    	
	    	$excel->getActiveSheet()->SetCellValue('A'.$i, date('d.m.Y', strtotime($row->date_created)));
	    	$excel->getActiveSheet()->SetCellValue('B'.$i, $row->last_name);
	    	$excel->getActiveSheet()->SetCellValue('C'.$i, $row->first_name);
	    	$excel->getActiveSheet()->SetCellValue('D'.$i, $row->email);
	    	$excel->getActiveSheet()->SetCellValue('E'.$i, $row->job);
	    	$excel->getActiveSheet()->SetCellValue('F'.$i, $row->test_name);
	    	$excel->getActiveSheet()->SetCellValue('G'.$i, '');
	    	$excel->getActiveSheet()->SetCellValue('H'.$i, '');
	    	/*
			$total_price += $row->oi_price;
			$total_sales_price += $row->oi_quantity * $row->oi_product_sales_price;
			$profit_price = ($total_sales_price - $total_price);
			*/
			if ($i%2 == 0)
			{
				$excel->getActiveSheet()->duplicateStyleArray(
			      array(
			        'fill' => array(
			             'type'   => PHPExcel_Style_Fill::FILL_SOLID,
			             'startcolor' => array(
			                'rgb' => 'C0C0C0'
			             )
			          ),
			      ),
			      'A'.$i.':H'.$i
				);	
			}
	
	
			$excel->getActiveSheet()->duplicateStyleArray(
				array(    	 		
	 	 		'borders' => array(
			        'right'  => array(
	                	'style' => PHPExcel_Style_Border::BORDER_THIN,
		                'color' => array('rgb' => '000000')                	
	             		),		         	          
			        'bottom'  => array(
	                	'style' => PHPExcel_Style_Border::BORDER_THIN,
		                'color' => array('rgb' => '000000')                	
	             		),
	 	 		),
		      ),
		      'A'.$i.':H'.$i
			);	
			
	    	//$price_total += $row->oi_price;
	
	    	$i++;
	    }
    }
    
	$excel->getActiveSheet()->duplicateStyleArray(
      array(
        'fill' => array(
             'type'   => PHPExcel_Style_Fill::FILL_SOLID,
             'startcolor' => array(
                'rgb' => '800080'
             )
          ),
         'font'  => array(
         	'name' => 'Arial',
            'bold' => true,
            'size' => '9',
            'color' => array('rgb' => 'FFFFFF')
         ),
         'alignment' => array(
            'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
       	),
		'borders' => array(
			'right'  => array(
            	'style' => PHPExcel_Style_Border::BORDER_THIN,
	        	'color' => array('rgb' => '000000')                	
            ),		         	          
		    'bottom'  => array(
            	'style' => PHPExcel_Style_Border::BORDER_THIN,
	            'color' => array('rgb' => '000000')                	
             ),
		    'top'  => array(
            	'style' => PHPExcel_Style_Border::BORDER_THIN,
	            'color' => array('rgb' => '000000')                	
             ),
 	 	),
      ),
      'A4:H4'
	);
    		
	//$excel->getActiveSheet()->SetCellValue('A'.$i, 'TOTAL');
	//$excel->getActiveSheet()->SetCellValue('M'.$i, $total_price);
	//$excel->getActiveSheet()->SetCellValue('N'.$i, $total_sales_price);
	//$excel->getActiveSheet()->SetCellValue('O'.$i, $profit_price);
			
	if ($i%2 == 0)
	{
		$excel->getActiveSheet()->duplicateStyleArray(
	      array(
	        'fill' => array(
	             'type'   => PHPExcel_Style_Fill::FILL_SOLID,
	             'startcolor' => array(
	                'rgb' => 'C0C0C0'
	             )
	          ),
	      ),
	      'A'.$i.':H'.$i
		);	
	}
					
	$excel->getActiveSheet()->duplicateStyleArray(
	      array(	      
	         'font'  => array(
	         	'name' => 'Arial',
	            'bold' => true,
	            'size' => '9',
	            'color' => array('rgb' => '800080')
	         ),
			'borders' => array(         	          
			    'bottom'  => array(
	            	'style' => PHPExcel_Style_Border::BORDER_THIN,
		            'color' => array('rgb' => '000000')                	
	             ),
	 	 	),	      ),
	      'A'.$i.':H'.$i
		);		

	$filename = (!empty($type)) ? str_replace(" ", "_", $type) . "_Results.xls" : "Results_".date('Y-m-d').".xls";  
	$this->excel->send_to_browser($filename);
?>